using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using AutumnEngine.Modules;
using System.Diagnostics;
using AutumnEngine;

namespace AutumnEngine.Modules
{
    /// <summary>
    /// Handles debug drawing.
    /// </summary>
    public class DebugModule : Module
    {
        internal SpriteFont Font
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the debug text. Each KeyValuePair is drawn, in the format of Key : Value.
        /// Values are not automatically updated.
        /// </summary>
        /// <value>The debug text.</value>
        public Dictionary<string, object> DebugText
        {
            get;
            set;
        }

        int frame = 0;

        /// <summary>
        /// Creates this instance.
        /// </summary>
        public override void Create()
        {
            DebugText = new Dictionary<string, object>();
            DebugText.Add("Frames", 0);
            DebugText.Add("Last Log Message", "");
#if ZUNE
            Font = Engine.Modules.EmbeddedContentManager.Load<SpriteFont>("DebugFontZune");
#endif
#if XBOX
            Font = Engine.Modules.EmbeddedContentManager.Load<SpriteFont>("DebugFont360");
#endif
#if WINDOWS
            Font = Engine.Modules.EmbeddedContentManager.Load<SpriteFont>("DebugFontWin");
#endif
            base.Create();
        }

        /// <summary>
        /// Draws this instance.
        /// </summary>
        public override void Draw()
        {
            frame++;
            DebugText["Frames"] = frame;


            string tota = "";
            foreach (KeyValuePair<string, object> k in DebugText)
            {
                string form = String.Format("{0} : {1}", k.Key, k.Value);
                tota += form;
                tota += "\n";
                
            }
            Engine.SpriteBatch.DrawString(Font, tota, Vector2.Zero, Engine.Modules.Settings.DebugColor);
            base.Draw();
        }
    }
}